package com.espirit.file;

import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;

public class NFile {
	
	private Path path;
	
	private BasicFileAttributes attributes;
	
	public NFile(Path path,BasicFileAttributes attributes){
		this.path = path;
		this.attributes = attributes;
	}
	
	public Path getPath() {
		return path;
	}
	
	public BasicFileAttributes getAttributes() {
		return attributes;
	}
	

	public boolean isSymbolicLink() {
		return this.attributes==null ? null : attributes.isSymbolicLink();
	}

	public boolean isDirectory() {
		return this.attributes==null ? null : attributes.isDirectory();
	}

	public boolean isRegularFile() {
		return this.attributes==null ? null : attributes.isRegularFile();
	}

	public FileTime getCreationTime() {
		return this.attributes==null ? null : attributes.creationTime();
	}

	public FileTime getLastAccessTime() {
		return this.attributes==null ? null : attributes.lastAccessTime();
	}

	public FileTime getLastModifiedTime() {
		return this.attributes==null ? null : attributes.lastModifiedTime();
	}

	public boolean isOther() {
		return this.attributes==null ? null : attributes.isOther();
	}

	public long getSize() {
		return this.attributes==null ? null : attributes.size();
	}
	
	public Path getRelativePath(String rootPath){
		if (this.getPath()==null) {
			return null;
		}
		return FileSystems.getDefault().getPath(rootPath).relativize(path);
	}
	
	public Path getRelativePath(Path rootPath){
		if (this.getPath()==null) {
			return null;
		}
		return rootPath.relativize(path);
	}


	@Override
	public String toString() {
		return "File [path=" + path + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NFile other = (NFile) obj;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		return true;
	}
	
}
